package com.itheima.work02;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class SetDemo {
    public static void main(String[] args) {
        Set<String> str = new TreeSet<>();

        str.add("刘备");
        str.add("关羽");
        str.add("张飞");
        str.add("刘备");
        str.add("张飞");

        System.out.println("集合大小" + str.size());

        System.out.println("使用迭代器遍历集合，并打印每个元素");
        Iterator<String> iterator = str.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            System.out.println(next);
        }

        System.out.println("使用增强for遍历集合，并打印每个元素");
        for (String s:str){
            System.out.println(s);
        }
    }
}
